package com.aaa.hospital.ManagementEnd.service.Impl;

import com.aaa.hospital.ManagementEnd.mapper.MedicineMapper;
import com.aaa.hospital.ManagementEnd.mapper.prescriptionDao;
import com.aaa.hospital.ManagementEnd.pojo.Examine;
import com.aaa.hospital.ManagementEnd.pojo.Medicine;
import com.aaa.hospital.ManagementEnd.pojo.Prescription;
import com.aaa.hospital.ManagementEnd.service.PrescriptionService;
import com.aaa.hospital.ManagementEnd.util.PrescriptionDB;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PrescriptionServiceImpl implements PrescriptionService {

@Autowired
private prescriptionDao prescriptionDao;

@Autowired
private MedicineMapper medicineMapper;



    @Override
    public List<Prescription> queryAll() {
        return prescriptionDao.queryAll();
    }

    @Override
    public boolean ypinsert(Integer ypid, Integer diaid,Prescription pertion,Integer num) {
        Prescription prescription = prescriptionDao.queryById(ypid, diaid);
        if (prescription!=null){
            System.out.println(num+"数量");
            System.out.println(ypid+"药品id");
             Medicine medicine = medicineMapper.ByYpId(ypid);
            System.out.println(medicine+"aaabbbb");
              Integer num1 = medicine.getNum(); //获取库存数量
            System.out.println(num1+"库存数量");
            Integer ypnum = prescription.getYpnum(); //获取拟定购买数量
            System.out.println(ypnum+"拟定购买数量");
            if (num1 >= (ypnum+num)) {//判断数量是否充足
               return prescriptionDao.addNum(ypid, num);//添加药品拟定清单
            }
            return false;
        }else {
        return  prescriptionDao.ypinsert(pertion);}
    }


    @Override
    public boolean minusNum(Integer diaid,Integer ypid, Integer num) {
        return prescriptionDao.minusNum(diaid, ypid, num);
    }

    @Override
    public List<Prescription> selectAll(Integer diaid) {
        return prescriptionDao.selectAll(diaid);
    }

    @Override
    public boolean delByDiaid(Integer diaid) {
        return prescriptionDao.delByDiaid(diaid);
    }

    @Override
    public Prescription queryById(Integer ypid, Integer diaid) {
        return prescriptionDao.queryById(ypid, diaid);
    }

    @Override
    public boolean delById(Integer ypid, Integer diaid) {
        return prescriptionDao.delById(ypid, diaid);
    }

    @Override
    public List<PrescriptionDB> preList(Integer diaid, Date time) {
        return prescriptionDao.preList(diaid, time);
    }


    @Override
    public Examine EXById(Integer id) {
        return prescriptionDao.EXById(id);
    }


}
